<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of category_model
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Counter_model extends CI_Model {

    //put your code here


    function __construct() {
        parent::__construct();
        log_message('debug', 'Init Model Initialized');
    }
    function make_count($type='CAR') {
            $sql = "Select count(*)as total from make where type='$type'";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
    }

    function model_count($type='CAR',$make_id=NULL) {
        if ($make_id) {
            $sql = "Select count(*)as total from model where make_id='$make_id' and type='$type'";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
        }
    }
    function version_count($type='CAR',$model_id=NULL) {
        if ($model_id) {
            $sql = "Select count(*)as total from version where model_id='$model_id' and type='$type'";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
        }
    }
     function state_count($cat_id=NULL) {
        if ($cat_id) {
            $code = trim($cat_id);
            $sql = "Select count(*)as total from state where country_id='$code'";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
        }
    }
   function city_count($cat_id=NULL) {
        if ($cat_id) {
            $code = trim($cat_id);
            $sql = "Select count(*)as total from city where state_id='$code'";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
        }
    }
    function feature_group_count($type=NULL)
    {
        $sql="Select count(*) as total from feature where type='$type' and slno='0'";
        $query=$this->db->query($sql);
        $row=$query->row();
        if($row->total!=0)
            return $row->total;
        else
            return '0';
    }
    function feature_count($type=NULL,$code=NULL)
    {
        $sql="Select count(*) as total from feature where slno!=0 and type='$type' and code='$code' ";
        $query=$this->db->query($sql);
        $row=$query->row();
        if($row->total!=0)
            return $row->total;
        else
            return '0';
    }
     function news_count() {
            $sql = "Select count(*)as total from news ";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
    }

	
}
